package com.zz.chenko.sys.service.impl;

import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.zz.chenko.sys.dao.UserRoleDao;
import com.zz.chenko.sys.entity.UserRole;
import com.zz.chenko.sys.service.UserRoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 用户-角色  关系表 服务实现类
 * </p>
 *
 * @author Zhong
 * @since 2017-05-16
 */
@Service
public class UserRoleServiceImpl extends ServiceImpl<UserRoleDao, UserRole> implements UserRoleService {

    @Autowired
    private UserRoleDao userRoleDao;

    /**
     * 通过用户id和角色id列表添加
     *
     * @param userId
     * @param roleIdList
     * @throws Exception
     */
    @Override
    public void saveByUserIdAndRoleIdList(Long userId, List<Long> roleIdList) throws Exception {
        try {
            for (Long roleId : roleIdList) {
                UserRole userRole = new UserRole();
                userRole.setUserId(userId);
                userRole.setRoleId(roleId);
                userRoleDao.insertAllColumn(userRole);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
